package com.lichhao.system.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.lichhao.common.dao.BaseDao;
import com.lichhao.common.service.BaseService;
import com.lichhao.common.util.QueryParam;
import com.lichhao.system.dao.OmAreaDao;
import com.lichhao.system.model.OmAreaBean;

@Service("omAreaService")
public class OmAreaService extends BaseService<OmAreaBean> {

	private OmAreaDao omAreaDao;
	/*
	public String queryList(QueryParam queryParam) {

		List<OmAreaBean> listTotal = omAreaDao.getMongoTemplate().findAll(
				OmAreaBean.class);

		int page = queryParam.getPageNumber();
		int total = listTotal.size();
		String text = "{" + "\"page\":" + page + ",\"total\":" + total
				+ ",\"rows\":[";

		Query query = new Query();

		if (!StringUtils.isEmpty(queryParam.getQuery())) {
			query.addCriteria(Criteria.where(queryParam.getQtype()).is(
					queryParam.getQuery()));
		}
		query.skip(queryParam.getSkip()).limit(queryParam.getLimit()).sort()
				.on(queryParam.getSortname(), queryParam.getSortorder());

		List<OmAreaBean> list = omAreaDao.getMongoTemplate().find(query,
				OmAreaBean.class);

		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		Date date = null;
		String str2 = "";
		Map<String, Object> map = null;
		for (int i = 0; i < list.size(); i++) {
			map = list.get(i).toMap();
			date = (Date) map.get("createDate");
			map.put("createDate", simpleDateFormat.format(date));
			// str = JSONObject.fromObject(map).toString();
			if (i == list.size() - 1) {
				str2 = "{" + "\"areaId\":" + map.get("areaId") + ","
						+ "\"areaName\":\"" + map.get("areaName") + "\","
						+ "\"areaCode\":\"" + map.get("areaCode") + "\","
						+ "\"parntAreaId\":" + map.get("parntAreaId") + ","
						+ "\"areaDesc\":\"" + map.get("areaDesc") + "\","
						+ "\"createDate\":\"" + map.get("createDate") + "\"}";

			} else {
				str2 = "{" + "\"areaId\":" + map.get("areaId") + ","
						+ "\"areaName\":\"" + map.get("areaName") + "\","
						+ "\"areaCode\":\"" + map.get("areaCode") + "\","
						+ "\"parntAreaId\":" + map.get("parntAreaId") + ","
						+ "\"areaDesc\":\"" + map.get("areaDesc") + "\","
						+ "\"createDate\":\"" + map.get("createDate") + "\"},";

			}
 
			text += str2;

		}
		// String text = JSONObject.fromObject(list).toString();

		// String text = JSONArray.fromObject(list).toString();
		text += "]}";

		// return text;
		return text;

	}
	*/
	@Autowired
	@Qualifier("omAreaDao")
	@Override
	public void setBaseDao(BaseDao<OmAreaBean> omAreaDao) {
		this.baseDao = omAreaDao;
		this.omAreaDao = (OmAreaDao) omAreaDao;
	}
	
	public OmAreaDao getOmAreaDao() {
		return omAreaDao;
	}
	
	
}
